package com.zhiyume.service;

import com.zhiyume.dao.api.TExtensionMapper;
import com.zhiyume.dao.entity.*;
import com.zhiyume.shiro.AdminSecurityManager;
import com.zhiyume.service.util.DateUtil;
import com.zhiyume.service.util.GenerateKeyUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class ExtentsionService {
    @Autowired
    TExtensionMapper tExtensionMapper;

    public TExtension getExtentsion(TExtension tExtension){
        TExtensionCriteria t = new TExtensionCriteria();
        TExtensionCriteria.Criteria c = t.createCriteria();
        if(tExtension.getId()!=null && tExtension.getId()!=0L){
            c.andIdEqualTo(tExtension.getId());
            return tExtensionMapper.selectByExample(t).get(0);
        }
        return new TExtension();
    }

    public Long addExtension(TExtension tExtension){
        TAdminSys sysUser = AdminSecurityManager.getSessionTAdminSys();
        long id = GenerateKeyUtil.generationPK();
        tExtension.setId(id);
        tExtension.setCreateTime(DateUtil.getNow());
        tExtension.setCreateId(sysUser.getId());
        tExtension.setScheme(tExtension.getScheme());
        tExtension.setStatus(tExtension.getStatus());
        tExtension.setParam1(tExtension.getParam1());
        tExtension.setParam2(tExtension.getParam2());
        tExtension.setParam3(tExtension.getParam3());
        tExtension.setParam4(tExtension.getParam4());
        tExtension.setParam5(tExtension.getParam5());
        tExtension.setPlatform(tExtension.getPlatform());
        tExtensionMapper.insert(tExtension);
        return tExtension.getId();
    }


}
